package sort;

import com.sun.deploy.util.StringUtils;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

import java.util.Arrays;

public class BubbleSort {

    public static void main(String[] args) {
        int[] arr= {8,4,3,1,4,8,3,51,4,35,4};

        bubbleSort(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }




    public static void bubbleSort(int[] arr){
        int size = arr.length;
        int temp = 0;
        boolean flag = false;
        for (int i = 0; i < size-1; i++) {
            for (int j = 0; j < size - i-1; j++) {
                if (arr[j]>arr[j+1]){
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    flag = true;
                }
            }
            if (flag){
                flag = false;
            }else
            {
                break;
            }
        }
    }

}
